<!-- 结构 -->
<template>
    <div class="login_container">
        <img src="../assets/images/login1.jpg" alt="" class="img1">
        <div class="title">
            <!-- <img src="../assets/images/title3.png" alt="" class="img2"> -->
            <h1>优秀成果后台管理</h1>
            <h2>BACKGROUND MANAGEMENT OF OUTSTANDING ACHIEVEMENT</h2>
        </div>
        <div class="login_box">

            <!-- 头像区域 -->
            <div class="avatar_box">
                <img src="../assets/images/1.jpg" alt="">
            </div>

            <!-- 登陆表单区域 -->
            <!-- ref被用来给元素或子组件注册引用信息,引用信息将会注册在父组件的 $refs对象上。通过$ref引用 -->
            <el-form 
            :model="loginForm"
            :rules="rulesForm"
            ref="loginFormRef"   
            label-width="0px" 
            class="login_form">
                <!-- 用户名 -->
                <el-form-item prop="username">
                    <el-input
                    v-model="loginForm.username"
                    prefix-icon="iconfont icon-yonghu"
                    class="ww"
                    ></el-input>
                </el-form-item>
                <!-- 密码 -->
                <el-form-item prop="password">
                    <el-input
                    v-model="loginForm.password"
                    type="password"
                    prefix-icon="iconfont icon-suozi"
                    ></el-input>
                </el-form-item>
                <!-- 登录 -->
                <el-form-item  class="btns">
                    <el-button type="primary" @click="submitForm">登录</el-button>
                    <el-button type="info" @click="resetForm">重置</el-button>
                </el-form-item>
            </el-form>
        </div>
    </div>
</template>

<!-- 行为 -->
<script>
import store from '../store/index'
export default {
    data() {
        return {
            // 登录表单的数据表绑定
            loginForm: {
                username: 'Admin',
                password: 'admin'
            },
            rulesForm: {
                username: [
                   { required: true, message: '请输入登录名称', trigger: 'blur' },
                   { min: 1, max: 10, message: '长度在 3 到 10 个字符', trigger: 'blur' }
                ],
                password: [
                   { required: true, message: '请输入登录密码', trigger: 'blur' },
                   { min: 3, max: 15, message: '长度在 3 到 15 个字符', trigger: 'blur' }
                ]
            }
        }
    },
    methods: {
        // 登录
        submitForm() {
            this.$refs.loginFormRef.validate(async (valid) => {
                if(!valid) return
                // 发起请求进行判断 coreService/user/login
                const {data: res}= await this.$http.post('coreService/user/login',this.loginForm)
                if(res.status != 20000 ) return this.$message.error("用户名或密码错误")
                this.$message.success("登陆成功")
                // 把token保存到sessionStorage中
                window.localStorage.setItem('token',res.data.token)
                this.$router.push("/home")
            })
        },
        // 重置
        resetForm() {
            this.$refs.loginFormRef.resetFields()
        }
    },
}
</script>

<!-- 样式 -->
<style lang="less" scoped>
.login_container {
    user-select: none;
    .img1 {
        width:100%;
        height:100%;
        position:fixed;
        background-size:100% 100%;
        filter: blur(7px);
        z-index: -1;
    }
    .title {
        position: absolute;
        top: 40px;
        left: 50%;
        transform: translate(-50%);
        color: white;
        h1 {
            font-size: 48px;
            letter-spacing: 5px;
            font-family: serif;
        }
        h2 {
            font-size: 17px;
            font-family: serif;
        }
    }
    .login_box {
        width: 400px;
        height: 300px;
        background-color: rgb(255, 255, 255);
        border-radius: 8px;
        position: absolute;
        left: 50%;
        top: 60%;
        transform: translate(-50%,-50%);
        background-color: rgba(130,187,232,0.1); // 透明
        border: 3px solid white;

        .avatar_box {
            width: 130px;
            height: 130px;
            border: 1px solid rgb(233, 228, 228);
            border-radius: 50%;
            padding: 8px;
            position: absolute;
            left: 50%;
            transform: translate(-50%,-50%);
            background-color: #fff;
            box-shadow: 0 0 10px #ddd;
            img {
                width: 100%;
                height: 100%;
                border-radius: 50%;
                background-color: #eee;
            }
        }
        
    }
    .login_form {
        position: absolute;
        bottom: 0;
        width: 100%;
        padding: 0 10px;
        box-sizing: border-box;
    }
    .btns {
        display: flex;
        justify-content: flex-end;
    }
    .login-form-input .el-input__inner {
        background-color: rgba(130,187,232,0.1);
    }
}
</style>>